/**
 *
 */
package com.angel.architecture.io.rowProcessors;

import com.angel.architecture.daos.ParameterAreaDAO;
import com.angel.architecture.persistence.beans.ParameterArea;
import com.angel.common.helpers.StringHelper;
import com.angel.data.generator.annotations.Inject;
import com.angel.io.annotations.ColumnRow;
import com.angel.io.annotations.RowChecker;
import com.angel.io.annotations.RowProcessor;
import com.angel.io.annotations.RowProcessorCommand;
import com.angel.io.exceptions.InvalidRowDataException;

/**
 * @author William
 *
 */
@RowProcessorCommand
	(
		columnsRow = {
			@ColumnRow( columnName = ParameterAreaAnnotationRowProcessorCommand.NAME_COLUMN, aliases = {"Nombre del Area"} ),
			@ColumnRow( columnName = ParameterAreaAnnotationRowProcessorCommand.DESCRIPTION_COLUMN, aliases = {"Descripcion del Area"} )
		}
	)
public class ParameterAreaAnnotationRowProcessorCommand {

	public static final String NAME_COLUMN = "name";
	public static final String DESCRIPTION_COLUMN = "description";

	@Inject
	private ParameterAreaDAO parameterAreaDAO;

    @RowChecker(columnsParameters = {})
    public void checkRowData(String name, String description) throws InvalidRowDataException {
		boolean areAllNotEmpty = StringHelper.areAllNotEmpty(name, description);
		if(!areAllNotEmpty){
			throw new InvalidRowDataException("Some row data are NULL - " +
					"name: [" + name + "] - " +
					"description: [" + description + "].");
		}
		ParameterArea parameterArea = this.getParameterAreaDAO().findUniqueOrNullByName(name);
		if(parameterArea != null){
			throw new InvalidRowDataException("Parameter area exist with name [" + name + "].");
		}
    }

	@RowProcessor(columnsParameters = {}, object = ParameterArea.class, inject = true)
	public ParameterArea processRow(ParameterArea parameterArea, String name, String description) {
        return parameterArea;
    }

	/**
	 * @return the parameterAreaDAO
	 */
	public ParameterAreaDAO getParameterAreaDAO() {
		return parameterAreaDAO;
	}

	/**
	 * @param parameterAreaDAO the parameterAreaDAO to set
	 */
	public void setParameterAreaDAO(ParameterAreaDAO parameterAreaDAO) {
		this.parameterAreaDAO = parameterAreaDAO;
	}
}
